package com.peng.mybatis.executor.statement;

import com.peng.mybatis.executor.Executor;
import com.peng.mybatis.mapping.BoundSql;
import com.peng.mybatis.mapping.MappedStatement;
import com.peng.mybatis.session.ResultHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

public class SimpleStatementHandler extends BaseStatementHandler {

    public SimpleStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject,
                                  ResultHandler resultHandler, BoundSql boundSql) {
        super(executor, mappedStatement, parameterObject, resultHandler, boundSql);
    }

    @Override
    protected Statement instantiateStatement(Connection connection) throws SQLException {
        return connection.createStatement();
    }

    @Override
    public void parameterize(Statement statement) {
        // 无需处理
    }

    @SuppressWarnings("all")
    @Override
    public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
        String sql = boundSql.getSql();
        statement.executeQuery(sql);
        return resultSetHandler.handleResultSet(statement);
    }

}
